Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Xml
Imports System.Collections.ObjectModel
Imports Microsoft.Health.PatientConnect
Imports Microsoft.Health
Imports Microsoft.Health.ItemTypes
Imports Microsoft.Health.Web
Imports System.Globalization

Friend Class Utilities
    Public Shared Function XmlFromDateTime(ByVal dateTime As DateTime)
        Return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ", CultureInfo.InvariantCulture)
    End Function

    ''' <summary>
    ''' Get value from Health vault 
    ''' </summary>
    ''' <typeparam name="T">Generic type</typeparam>
    ''' <param name="typeID">TypeId for HealthRecordItem</param>
    ''' <param name="accessor">Reference to HealthRecordAccessor</param>
    ''' <returns>Object of generics</returns>
    Public Shared Function GetHealthRecordItemValue(Of T As Class)(ByVal typeID As Guid, ByVal accessor As HealthRecordAccessor) As T
        Dim searcher As New HealthRecordSearcher(accessor)
        searcher.Filters.Add(New HealthRecordFilter(typeID))
        Dim items As HealthRecordItemCollection = searcher.GetMatchingItems()(0)
        If items IsNot Nothing AndAlso items.Count > 0 Then
            Return TryCast(items(0), T)
        Else
            Return Nothing
        End If
    End Function
End Class

